package com.aode.utils.sharedhelper;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.HashMap;
import java.util.Map;

public class SharedHelper {
    private Context context;
    public SharedHelper(){

    }
    public SharedHelper(Context context){
        this.context = context;
    }

    //定义一个保存数据的方法
    public void save(String userId){
        SharedPreferences sharedPreferences = context.getSharedPreferences("user",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("userId",userId);
        editor.commit();
    }

    //定义一个读取SP文件的方法
    public Map<String, String> read(){
        Map<String, String> data = new HashMap<>();
        SharedPreferences sharedPreferences = context.getSharedPreferences("user",Context.MODE_PRIVATE);
        data.put("userId",sharedPreferences.getString("userId",""));
        return data;
    }
}
